<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" > 

<html>
<head>
<base href="<%=basePath%>">
<title>病历列表</title>
<link rel="stylesheet" type="text/css" href="./js/bootstrap-3.3.5-dist/css/bootstrap.css" />
<link href="./js/metisMenu/metisMenu.min.css" rel="stylesheet">
<link href="./css/sb-admin/sb-admin-2.css" rel="stylesheet">
<link rel="stylesheet" href="./js/font-awesome/css/font-awesome.min.css">
<link href="./css/base.css" rel="stylesheet">
<link rel="stylesheet" href="./js/bootstrap-table/bootstrap-table.min.css">
<link rel="stylesheet" href="./js/bootstrap-multiselect/bootstrap-multiselect.css"/>
<link rel="stylesheet" href="./js/bootstrap-3.3.5-dist/css/bootstrap-datetimepicker.css">
<script type="text/javascript" src="./js/jquery-1.11.3.min.js"></script>
<script type="text/javascript" src="./js/bootstrap-3.3.5-dist/js/bootstrap.js"></script>
<script src="./js/bootstrap-table/bootstrap-table-all.js"></script>
<script src="./js/bootstrap-table/bootstrap-table-zh-CN.min.js"></script>
<script type="text/javascript" src="./js/metisMenu/metisMenu.js"></script>
<script src="./js/bootstrap-multiselect/bootstrap-multiselect.js"></script>
<script src="./js/bootstrap-3.3.5-dist/js/bootstrap-datetimepicker.js"></script>
<script src="./js/bootstrap-3.3.5-dist/js/bootstrap-datetimepicker.zh-CN.js"></script>
<script src="./js/bootstrap-jquery-plugin/jquery.bootstrap.js"></script>
<script type="text/javascript" src="./js/common.js"></script>
<script type="text/javascript" src="./js/xss.js"></script>
</head>
<body>
<jsp:include page="../template/head.jsp" />
<jsp:include page="../template/leftnav.jsp" />
<div id="page-wrapper">
	<div>
		<h1>病历列表</h1>
	</div>
	<div class="content">
		<form class="form-inline">
			<div class="form-group">
				<label for="userName">用户名：</label>
				<input type="text" id="userName" class="form-control" placeholder="请输入用户名" onkeyup="filters(this)" onchange="filters(this)">
			</div>
			<div class="form-group">
				<button class="btn  search-btn" id="search">搜索</button>
				<button id="reset" class="btn btn-default">重置</button>
			</div>
		</form>
		 <table id="table" data-toolbar="#toolbar" data-toggle="table" data-row-style="rowStyle" data-classes="table  table-no-bordered"
	           data-minimum-count-columns="2"  data-cache="false" data-pagination="true"  data-striped="data-striped"
	           data-page-list="[5, 10, 20, 50]"  data-query-params="tableQueryParams" style="word-break:break-all;"
	           data-side-pagination="server" data-page-size=10 >
	           <thead>
				<tr class="headTr">
					<th data-field="userCode" data-width="20%" >用户ID</th>
					<th data-field="username" data-width="10%" >用户名</th>
					<th data-field="name" data-width="15%" >病历名</th>
					<th data-field="zhushu" data-width="15%" >主诉</th>
					<%--<th data-field="medicalrecord" data-width="15%" >病历</th>--%>
					<th data-field="createdTime" data-width="20%" data-formatter="dateFormatter">创建时间</th>
					<th data-field="operation" data-width ="20%" data-formatter="operFormatter">操作</th>
				</tr>
			</thead>
	    </table>
	    <div id="adminperTemp" style="display:none">
			<ul class="list-inline">

				<li role="presentation"><a class="btn btn-primary">问诊</a></li>
				<li role="presentation"><a class="btn btn-primary">病历</a></li>
				<%--<li role="presentation"><a class="btn btn-primary">解读</a></li>--%>
			</ul>
		</div>
    </div>
</div>

<div id="eidtwrap" style="display:none">
  <form id="editform" role="form" class="form-horizontal">
    <div class="form-group">
    	<label for="active" class="col-sm-3 control-label" style="margin-top:5px">建议:</label>
    	<div class="col-sm-8">
      		<textarea class="form-control" id="active1" placeholder="请输入建议" onkeyup="filters(this)" onchange="filters(this)"></textarea>
    	</div>
    	<br>
    	<br>
    </div>
  </form>
</div>

<div id="detailwrap" style="max-height:90%;display:none;overflow: hidden;overflow-y: scroll;">
	<span id="detail">

	</span>

	<div style="margin-top: 20px">
		<label style="color: red">病历解读</label>
		<br>
		<textarea rows="" cols="" style="width: 99%;height: 200px;resize: none"></textarea>
	</div>

</div>

<div id="askwrap" style="display:none">
	<span id="ask">

	</span>
</div>

<script>

$(function () {
	
	"use strict";
	
	$('#table').bootstrapTable('refresh', {
		query : {
			offset: 0
		},
		url : "./medicalRecord/getMedicalRecordList",
		silent : true
	});

	$('#search').on('click', function (e) {
		e.preventDefault();
		searchOrder();
	});
	
});

function dateFormatter(value, row){
	if(value!=null){
		return getSmpFormatDateByLong(value, true);
	}else{
		return '-';
	}
}

function tableQueryParams(params) {
	var queryObj = getQueryObject();
	var newParams = $.extend(params,queryObj);
	return newParams;
}
	
function getQueryObject(){
	var queryObj;
	var userName = $("#userName").val();

	var queryObj = {
		userName : userName
	}
	
	if(userName ==""){
		delete queryObj.userName;
	}

	return queryObj;
}
	
function searchOrder(){
	var queryObj = getQueryObject();
	$('#table').bootstrapTable('refresh', {
		query : {
			offset: 0
		},
		url : "./medicalRecord/getMedicalRecordList",
		silent : true
	});
}

function operFormatter(value, row) {
	var operTemp = $("#adminperTemp").clone();
	var lis = operTemp.find("ul li");
	lis.eq(0).find("a").attr("onClick", "ask(\""
			+encodeURIComponent(row.askrecord)+"\")");
	lis.eq(1).find("a").attr("onClick", "detail(\""
			+encodeURIComponent(row.medicalrecord)+"\")");
	/*lis.eq(1).find("a").attr("onClick", "editSysCaseHistoryActive(\""
		+row.id+"\")");*/

	return operTemp.html();
}

function ask(data){
	$("#askwrap").show();
	var d = decodeURIComponent(data);
	if(d==''){
		alert('不存在问诊过程')
		return;
	}
	var list = JSON.parse(d);
	var html = '';
	for(var x=0;x<list.length;x++){
		if(x==0){
			html += '<span>'+list[x].question+'</span><br>' + '<span>'+list[x].answer+'</span><br><br>'
		}else{
			html += '<span>问题：'+list[x].question+'</span><br>' + '<span>答案：'+list[x].answer+'</span><br><br>'
		}

	}
	$("#ask").html(html);
	$("#askwrap").dialog({
		title   : "问诊详情",
		'class' :  "mydialog",
		onClose : function() {
			$(this).dialog("close");

		},
		buttons : [{
			text : "关闭",
			'class' : "btn btn-primary",
			click : function() {

				$(this).dialog("close");
			}
		}]
	});
}

function detail(data){

	$("#detailwrap").show();
	var d = decodeURIComponent(data);
	$("#detail").html(d.replaceAll('\n','<br>'));
	$("#detailwrap").dialog({
		title   : "病历详情",
		'class' :  "mydialog",
		onClose : function() {
			$(this).dialog("close");

		},
		buttons : [{
			text : "关闭",
			'class' : "btn btn-primary",
			click : function() {

				$(this).dialog("close");
			}
		}]
	});
}

function editSysCaseHistoryActive(id){
   	$("#eidtwrap").show();
	$("#eidtwrap").dialog({
         	title   : "填写建议",
        	'class' :  "mydialog",
        	onClose : function() { 
         		 $(this).dialog("close");
         		 $("#active1").val('');
          	}, 
          	buttons : [{
          		text : "提交",
          		'class' : "btn btn-primary",
             	click : function() {
             		var active = $("#active1").val();
             		
                    $.ajax({
                     url: "./sysCaseHistory/editSysCaseHistoryActive",
                     data: {
                     	id :id,
						active : active
                     },
                     type: "POST",
                     dataType: 'json',
                     cache: false,
                     success: function (ret) {
                         if (ret.resultCode == 0) {
                             $.messager.popup(ret.msg);
                             $('#table').bootstrapTable('refresh', {
								query : {
									offset: 0
								},
								silent : true
							});
                            
                         }else{
                         	$.messager.popup(ret.msg);
                         }
                         $(this).dialog("close");
                     }
                 });
                 $(this).dialog("close");
                 $("#active1").val('');
             	}
             },{
             text : "关闭",
             'class' : "btn btn-default",
             click : function() {
                	 $(this).dialog("close");
                		$("#active1").val('');
             	}
         }]
     });
}
</script>
</body>
</html>